package org.springframework.session;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DelegatingIndexResolver<S extends Session> implements IndexResolver<S> {

	private final List<IndexResolver<S>> delegates;

	public DelegatingIndexResolver(List<IndexResolver<S>> delegates) {
		this.delegates = Collections.unmodifiableList(delegates);
	}

	@SafeVarargs
	public DelegatingIndexResolver(IndexResolver<S>... delegates) {
		this(Arrays.asList(delegates));
	}

	public Map<String, String> resolveIndexesFor(S session) {
		Map<String, String> indexes = new HashMap<>();
		for (IndexResolver<S> delegate : this.delegates) {
			indexes.putAll(delegate.resolveIndexesFor(session));
		}
		return indexes;
	}
}
